function [converge, X, iterations, closure] = SimpleIterationsMethod( A, b, eps, max )
%Solves the system of linear equations
B = zeros(size(A,1), size(A, 2));
c = b;
for i = 1 : size(A, 1)
    c(i) = c(i) / A(i,i);
    for j = 1 : size(A, 2)
       if (i == j)
           B(i, j) = 0;
       else
           B(i, j) = - A(i, j) / A(i, i);           
       end;
    end;
end;
converge = true;
k = 1;
x0 = c;
xk = B * x0 + c;
norm_no = 1;
    coef = 0;
    if (norm(B, norm_no) > 1)
        norm_no = 2;
        if (norm(B, norm_no) > 1)
            norm_no = Inf;
            if (norm(B, norm_no) > 1)
                norm_no = 1;
                coef = 1;
            end;
        end;
    end;
    if (coef ~= 1)
        coef =  norm(B, norm_no) / (1 - norm(B, norm_no)) ;
    end;
while (norm(xk - x0, norm_no) * coef >= eps)
   x0 = xk;
   xk = B * x0 + c;
   k = k + 1;
   if (k == max && coef == 1)
       converge = false;
       break;
   end;
end

X = xk;
iterations = k;
closure = A * X - b;

end

